import 'package:my_flutter_core/utils/ui_interaction_utils.dart';
import 'package:permission_handler/permission_handler.dart';

/// Requests on device camera permission.
Future<bool> requestCameraPermissions() async {
  final status = await Permission.camera.request();

  if (status == PermissionStatus.permanentlyDenied) {
    showToast('访问相机权限已被永久禁止，请先在系统设置界面修改。');
    return false;
  } else if (status != PermissionStatus.granted) {
    showToast('请授权访问相机权限');
    return await requestCameraPermissions();
  }

  return true;
}

// /// Requests on device storage permission.
// static Future<bool> requestStoragePermissions() async {
//   final status = await Permission.storage.request();

//   if (status == PermissionStatus.permanentlyDenied) {
//     UserInteraction.showToast('访问内部存储权限已被永久禁止，请先在系统设置界面修改。');
//     return false;
//   } else if (status != PermissionStatus.granted) {
//     UserInteraction.showToast('请授权访问内部存储权限');
//     return await requestStoragePermissions();
//   }

//   return true;
// }

/// Requests on device locationWhenInUse permission.
Future<bool> requestLocationWhenInUsePermissions() async {
  final status = await Permission.locationWhenInUse.request();

  if (status == PermissionStatus.permanentlyDenied) {
    showToast('定位权限已被永久禁止，请先在系统设置界面修改。');
    return false;
  } else if (status != PermissionStatus.granted) {
    showToast('请授权定位权限');
    return await requestLocationWhenInUsePermissions();
  }

  return true;
}
